{extends file="./main.tpl"}
{block name=title}Entry{/block}
{block name=head}
<style type="text/css">
  .dateFormate {
    width: 2.5em;
    text-align: center;
    border: 0;
    vertical-alin: top;
    font-size: 10pt;
    line-height: 5px;
    font-weight: normal;
    color: gray;
  }
  input[name="y"] {
    width: 4em;
  }
</style>
<script type="text/javascript">
$(document).ready(function() {
  {if $isEdit == 1}
	{if $transactionArr.resellerId != 0}
	  setName();
	{/if}
	$("select#period").val({$transactionArr.period});
	{/if}
	{if $renew == 1}
	 changeDate();
	{/if}
	{if $isEdit != 1}
	  var year = $("select[name='startDateYear']").val();
	  var month = $("select[name='startDateMonth']").val();
	  var day = $("select[name='startDateDay']").val();
	  $("#endDate").val(year+"-"+month+"-"+day);
	{/if}
  if( {$success} == 1 )
  {
    showInsertSuccess();
  }
  if( {$success} == 2 )
  {
    showUpdateSuccess();
  }
  
  $("#state").autocomplete("getStateAuto.php", 
	{    
		width: 150,     
		matchContains: true,
		mustMatch: false,
		minChars: 0,
		//multiple: true,
		highlight: false,
		//multipleSeparator: ",",
		selectFirst: true,
		formatItem: function(data, i, n, value) {   
		  return  value.split("|")[0];
	  }
  }); 
  $("#state").result(function(event, data, formatted) {
	  $("#stateId").val(data[1]);
	  $("#stateNm").val(data[2]);
  });
  $("#holderNm").autocomplete("holderAuto.php", 
	{    
		width: 150,     
		matchContains: true,
		mustMatch: false,
		minChars: 0,
		//multiple: true,
		highlight: false,
		//multipleSeparator: ",",
		selectFirst: true,
		formatItem: function(data, i, n, value) {   
		  return  value.split("|")[0];
	  }
  }); 
  $("#holderNm").result(function(event, data, formatted) {
	  $("#holderId").val(data[1]);
	  $("#holderNmHidden").val(data[2]);
  });
});
function setName()
{      
	if($("#resellerId").val() > 0)
	{
		var dataString = "resellerId=" + $("#resellerId").val();
		$.ajax({
  		type: "GET",
  		url: "./getResellerData.php",
  		data: dataString,
  		dataType: 'json',
  		success:function(data){
  			$("#custName").val(data[0]);
  			$("#mobileNo").val(data[1]);
  			$("#stateId").val(data[2]);
  			$("#stateNm").val(data[3]);
  			$("#state").val(data[3]);
  			$("#cityId").val(data[4]);
  			$("#cityNm").val(data[5]);
  			$("#city").val(data[5]);
  			$("#resellerRate").val(data[6]);
  	  }
  	});		
	}
	else
	{
    $("#custName").val("");
    $("#mobileNo").val("");
    $("#stateId").val("");
    $("#stateNm").val("");
    $("#state").val("");
    $("#cityId").val("");
    $("#cityNm").val("");
    $("#city").val("");
    $("#resellerRate").val(0);
    $("#billAmount").val("");
	}
}
function getCity()
{
	if($("#state").val() != $("#stateNm").val())
	{
		$("#stateId").val('');
	}
	$("#city").autocomplete("getCityAuto.php?stateId=" + $("#stateId").val(),
	{    
		width: 150,     
		matchContains: true,
		mustMatch: false,
		minChars: 0,
		//multiple: true,
		highlight: false,
		//multipleSeparator: ",",
		selectFirst: true,
		formatItem: function(data, i, n, value) {   
		  return  value.split("|")[0];
	  }
  }); 
  $("#city").result(function(event, data, formatted) {
	  $("#cityId").val(data[1]);
	  $("#cityNm").val(data[2]);
  });
}
function chkCity()
{
	if($("#city").val() != $("#cityNm").val())
	{
		$("#cityId").val('');
	}
}
function chkHolder()
{
  if($("#holderNm").val() != $("#holderNmHidden").val())
	{
		$("#holderId").val('');
	}
}
function changeDate()
{
 var dataString = "period=" + $('#period').val() + "&startDateYear=" + $("select[name='startDateYear']").val() 
                      + "&startDateMonth=" + $("select[name='startDateMonth']").val() + "&startDateDay=" + $("select[name='startDateDay']").val();
	  $.ajax({
      url:  "./changeEndDate.php",
      cache: false,
      data: dataString,
      success: function(data){
        var year = data.split('-')[0];
        var month = data.split('-')[1];
        var day  = data.split('-')[2];
        $("#endDate").val(year+"-"+month+"-"+day);
        $("select[name='endDateYear']").val(year);
        $("select[name='endDateMonth']").val(month);
        $("select[name='endDateDay']").val(day);
        //$("select[name='startDateYear']").val();
    }
  });
}
function getRate()
{
  var dataString = "period=" + $('#period').val() + "&exchangeId=" + $('#exchangeId').val() + "&resellerRate=" + $('#resellerRate').val();
	  $.ajax({
      url:  "./getRate.php",
      cache: false,
      data: dataString,
      success: function(data){
        $("#billAmount").val(data);
    }
  });
}
function showInsertSuccess()
{
  $().toastmessage('showSuccessToast', "Data Submitted Successfully.....");
}
function showUpdateSuccess()
{
  $().toastmessage('showSuccessToast', "Data Updated Successfully.....");
}
{if $isEdit != 1}
	function checkSoftId()
	{
		if($('#softId').val() != 'Naman' && $('#softId').val() != 'Naman0')
		{
		  var dataString = "softId=" + $('#softId').val();
		    $.ajax({
	        url:  "./checkSoftId.php",
	        cache: false,
	        data: dataString,
	        dataType: 'json',
	        success: function(data){
	        if(data != 0)
	        {
	        	var r=confirm(data[0]);
	        	if (r==true)
		  		  {
		  		    window.location = "confirm.php?transactionId="+data[1]+"&exchange=1";
		  		  }
		  		else
		  		  {
		  		    $("#softId").val("Naman");
		  		    $("#softId").focus();
		  		  }
	        }
	      }
	    });
	  }
	}

function checkMobId()
{
	if($('#mobileNo').val() != '')
	{
	  var dataString = "mobileNo=" + $('#mobileNo').val();
	    $.ajax({
        url:  "./checkDemo.php",
        cache: false,
        data: dataString,
        dataType: 'json',
        success: function(data){
        if(data != 0)
        {
        	var r=confirm(data[0]);
        	if (r==true)
	  		  {
	  		    window.location = "confirm.php?transactionId="+data[1]+"&exchange=1";
	  		  }
	  		else
	  		  {
	  		  	$('#mobileNo').val("");
	  		  	$("#mobileNo").focus();
	  		  }
        }
      }
    });
  }
}
{/if}
</script>
{/block}
{block name=body}
<form action="{$smarty.server.PHP_SELF}" id="demoFrom" method="POST">
<input type="hidden" name="transactionId" value="{$transactionArr.transactionId}" />
<input type="hidden" name="resellerRate" id="resellerRate" value='0' />
<input type="hidden" name="renew" id="resellerRate" value='{$renew}' />
<input type="hidden" name="exchangeVal" id="resellerRate" value='{$exchangeVal}' />
<table class="confirmTable">
<tr>
	<td colspan="6" align="center"><h1>Give For Demo/Confirm</h1></td>
</tr>
<tr>
	<th class="thClass" colspan="6">
	  <select name="resellerId" id="resellerId" onchange="setName();">
	    <option value="0">Own</option>
	    {html_options values=$resellerArr.resellerMasterId output=$resellerArr.resellerName selected="{$transactionArr.resellerId}"}
	  </select>
	 </th>
</tr>
<tr>
	<th class="tdClass" align="left">Id: <input type="text" name="softId" id="softId" class="text w_10" required="required" autofocus="autofocus" {if $isEdit == 1}value="{$transactionArr.softwareId}"{else}value="Naman"{/if}/ {if $checkDate != 1} onblur="checkSoftId(); {/if}"></th>
	<th class="tdClass" align="left">Password: <input type="text" name="password"  value="{$transactionArr.password}" class="text w_10" required="required" /></th>
	<th class="tdClass" align="left">Name: <input type="text" name="custName" id="custName"  value="{$transactionArr.clientName}" class="text w_10" required="required" /></th>
	<th class="tdClass" align="left">Mobile No: <input type="text" name="mobileNo" id="mobileNo" value="{$transactionArr.mobile1}"  class="text w_10" required="required" onblur="checkMobId();"/></th>
	<th class="tdClass" align="left">State: <input type="text" name="state" id="state" {if $transactionArr.resellerId == 0} value="{$transactionArr.stateName}" {/if} class="text w_10" required="required" onblur="getCity();" />
	<input type="hidden" name="stateId" id="stateId" {if $transactionArr.resellerId == 0} value="{$transactionArr.stateId} {/if}" />
	<input type="hidden" name="stateNm" id="stateNm" {if $transactionArr.resellerId == 0} value="{$transactionArr.stateName} {/if}" />
	</th>
	<th class="tdClass" align="left">City: <input type="text" name="city" id="city" {if $transactionArr.resellerId == 0} value="{$transactionArr.cityName}"{/if} class="text w_10" required="required" onblur="chkCity();" />
  <input type="hidden" name="cityId" id="cityId" {if $transactionArr.resellerId == 0} value="{$transactionArr.cityId}"{/if} />
  <input type="hidden" name="cityNm" id="cityNm" {if $transactionArr.resellerId == 0} value="{$transactionArr.cityName}"{/if} />
  </th>
</tr>
<tr>
	<th class="tdClass" align="left">Period:
		<select name="period" id="period" onchange="changeDate(); getRate();">
			<option value="D">Demo</option>
			<option value="90">3 Months</option>
			<option value="182">6 Months</option>
			<option value="273">9 Months</option>
			<option value="364">12 Months</option>
	  </select>
  </th>
	<th class="tdClass" align="left">
		Exchange:<select name="exchangeId[]" id="exchangeId" multiple required="required" onblur="getRate();">
			{html_options values=$exchangeArr.exchangeId output=$exchangeArr.exchange selected=$exchangeSelectedArr}
	  </select>
  </th>
  <th class="tdClass" align="left" colspan="2">Start Date:
    {html_select_date prefix="startDate" time="{$transactionArr.date}" start_year="-3" end_year="+1" month_format="%m" field_order="DMY"  day_value_format="%02d" all_extra='onchange="changeDate()"'}
  </th>

  <th class="tdClass" align="left" colspan="2">End Date:
   {html_select_date prefix="endDate" start_year="-3" time="{$transactionArr.expiryDate}" end_year="+1" month_format="%m" field_order="DMY"  day_value_format="%02d" disabled={$transactionArr}}
   <input type="hidden" name="endDate" id="endDate" value="{$transactionArr.expiryDate}" />
  </th>
</tr>
<tr>
	<th class="tdClass" align="left">Rate: <input type="text" value="{$transactionArr.billAmount}" name="billAmount" id="billAmount" class="text w_10" required="required" /></th>
	<th class="tdClass" align="left">Pay Via:
  <select name="payVia">
	  {html_options values=$payViaArr.payViaId output=$payViaArr.payVia selected="{$transactionArr.payViaId}"}
	</select>
	</th>
	<th class="tdClass" align="left">Account Holder: <input type="text" name="holderNm" id="holderNm" class="text w_10" required="required" onchange="chkHolder();" {if $renew != 1}value="{$transactionArr.holderName}"{/if} />
	  <input type="hidden" name="holderId" id="holderId" class="text w_10" {if $renew == 0} value="{$transactionArr.accountHoderId}" {/if} />
	  <input type="hidden" name="holderNmHidden" id="holderNmHidden" class="text w_10" {if $renew == 0} value="{$transactionArr.holderName}"{/if} />
	<th class="tdClass" align="left">&nbsp;</th>
</tr>
<tr>
	<th class="tdClass" colspan="5" align="left">Notes: <textarea name="notes"  class="text w_40" />{$transactionArr.notes}</textarea></th>
</tr>
<tr>
	<th class="tdClass" colspan="6">
		<div class="submitButton"><input name="btnConfirm" type="submit" value=" Submit " /><span></span></div>
	</th>
</tr>
</table>
</form>
{/block}